<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .content-form {
    margin-bottom: -20px;
  }
  .content-paging {
    float:right;
    margin-right: 35px;
  }
  .add-btn {
    float: right;
    margin-top: -46px;
    margin-right: 10px;
  }
  .content-list {
    margin-top: 20px;
  }
  .content-radio {
    margin-top: -30px;
    margin-left: 150px;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>内容管理H5列表</span>
    </div>
    <!-- <content-radio class="content-radio" :value="value" @change-content="changeContent"></content-radio> -->
    <div class="line"></div>
    <content-form
      class="content-form"
      @on-success-valid="handleSubmit">
    </content-form>
    <h5-list :list="h5List" @to-editor="handleEditor" @delete-theme="deleteTheme"></h5-list>
    <!-- <h5-index></h5-index> -->
    <!-- <Button
      icon="md-add"
      type="primary"
      class="add-btn"
      @click="handleClick">
      添加内容
    </Button>
    <h5-modal @h5-valid="handleEdit"></h5-modal>
    <confirm-modal
      @confirm-valid="handleConfirm">
    </confirm-modal>
    <delete-modal
      @delete-valid="confirmDelete">
    </delete-modal>
    <content-list class="content-list" :list="historyData" @view-content="viewH5" @delete-content="deleteH5" @edit-content="handleClick"></content-list> -->
    <table-page
      class="content-paging"
      :dataCount="dataCount"
      @change-page="changePage"
      @change-page-size="changePageSize"
      :pageSize="pageSize">
    </table-page>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import ContentForm from '_c/content-form'
import TablePage from '_c/table-page'
import H5Modal from '_c/h5-modal'
import H5List from '_c/h5-list'
// import H5Index from '_c/h5-list/components/h5-index'
import ConfirmModal from '_c/confirm-modal'
import ContentList from '_c/content-list'
import ContentRadio from '_c/content-radio'
import DeleteModal from '_c/delete-modal'
export default {
  components: {
    ContentForm,
    TablePage,
    H5Modal,
    H5List,
    ContentList,
    ContentRadio,
    DeleteModal,
    ConfirmModal
    // H5Index
  },
  data () {
    return {
      page: 1,
      title: '内容管理H5列表',
      value: 'H5',
      rows: 20,
      confirmData: {}
    }
  },
  computed: {
    ...mapState({
      h5List: state => state.h5Content.h5List,
      dataCount: state => state.h5Content.h5DataCount,
      historyData: state => state.h5Content.h5HistoryData,
      pageSize: state => state.h5Content.h5PageSize
    })
  },
  methods: {
    ...mapActions([
      'getH5List',
      'getH5ListCurrentRow',
      'editH5ListData',
      'updateModalState',
      'updateDeleteModalState',
      'updateConfirmModalState',
      'changeH5ListPage',
      'changeH5ListPageSize'
    ]),
    handleSubmit (playload) {
      this.postData = {
        ctime: playload.ctime,
        title: playload.title,
        type: 0
      }
      this.getH5List(this.postData)
    },
    handleEditor (item) {
      // console.log(item)
    },
    deleteTheme (item) {
      // console.log(item)
    },
    showPreview (item) {
      // console.log(item)
    },
    handleClick (item) {
      let newRow = {}
      this.id = item.id
      if (item.id) {
        newRow = Object.assign({}, item)
      }
      this.getH5ListCurrentRow(newRow)
      this.updateModalState(true)
    },
    handleEdit (playload, id) {
      // console.log(playload)
      // this.editGraphicListData(playload).then(
      //   this.getH5List({})
      // )
      this.confirmData = playload
      this.updateModalState(false)
      this.updateConfirmModalState(true)
    },
    handleConfirm () {
      this.editH5ListData(this.confirmData).then(
        setTimeout(() => {
          this.getH5List({
            page: this.page,
            type: 0,
            rows: this.rows
          })
        }, 100)
      )
      this.updateConfirmModalState(false)
    },
    changePage (index) {
      this.page = index
      this.changeH5ListPage(index)
      this.getH5List({
        type: 0,
        page: index,
        rows: this.rows
      })
    },
    changePageSize (value) {
      this.rows = value
      this.changeH5ListPageSize(value)
      this.changePage(this.page)
      this.getH5List({
        type: 0,
        rows: value
      })
    },
    viewH5 (index) {
      // console.log(index)
    },
    changeContent (value) {
      if (value === 'H5') {
        this.$router.push('/h5-content')
      } else if (value === '图文') {
        this.$router.push('/graphic')
      } else if (value === '视频') {
        this.$router.push('/video')
      }
    },
    deleteH5 (index) {
      this.index = index
      this.updateDeleteModalState(true)
    },
    confirmDelete () {
      this.updateDeleteModalState(false)
      this.h5List.splice(this.index, 1)
      this.changePage(this.page)
    }
  },
  created () {
    this.getH5List({
      type: 0
    })
  }
}
</script>
